//
//  HRZAPIRequest.m
//  EMarket
//
//  Created by 物联速通信息技术有限公司 on 2018/5/23.
//  Copyright © 2018 好日子. All rights reserved.
//

#import "HRZAPIRequest.h"

// Controllers

// Models
#import "HRZAPIResult.h"
// Views

// Vendors

// Categories

// Others
#import "URLMacros.h"

@interface HRZAPIRequest ()

@end

@implementation HRZAPIRequest

- (id)initWithAPIRequestType:(APIRequestType)type withSubPath:(NSString *)subPath {
    if (self = [super init]) {
        self.requestType = type;
        self.subUrl = subPath;
    }
    return self;
}


- (void)addParam:(id)param {
    [self.params addEntriesFromDictionary:(NSMutableDictionary*)param];
}

/** 请求结果数据 */
- (void)callBackFinishedWithDictionary:(NSDictionary *)dic {

    HRZAPIResult *result = [[HRZAPIResult alloc] initWithDictionary:dic];
    
    WEAKSELF
    if (result.success) {
        if (weakSelf.ServerSuce) {
            /** 数据为正常数据 */
            weakSelf.ServerSuce(result.dic);
        }
    } else {
        if (weakSelf.ServerFail) {
            /** 数据为异常数据 */
            weakSelf.ServerFail(result.message);
        }
    }
}

/** 请求数据结果失败 */
- (void)callBackFailed:(NSError *)error {
    WEAKSELF
    if (weakSelf.ServerFail) {
        weakSelf.ServerFail([NSString stringWithFormat:@"%@",error]);
    }
}

#pragma mark - ===============  Get  ===============
- (NSString *)fullUrl {
    return [NSString stringWithFormat:@"%@%@", kUrlBase,self.subUrl];
}
@end
